import { defHttp } from '@/utils/http/axios';

import { ErrorMessageMode } from '#/axios';
import { LoginParams, LoginResult, SessionUser } from '@/api/auth/model/authModel';
import { RouteRecordNormalized } from 'vue-router';

/**
 * 登录
 *
 * @param params login 参数
 * @param mode mode
 * @return token
 */
export function login(params: LoginParams, mode: ErrorMessageMode) {
  return defHttp.post<LoginResult>(
    {
      url: '/api/login/account',
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 获取当前登录用户
 *
 * @return SessionUser
 */
export function getCurrentUser() {
  return defHttp.get<SessionUser>({ url: '/api/auth/current/user' });
}

/**
 * 获取当前登录用户路由
 *
 * @return List<RouteRecordNormalized>
 */
export function getCurrentUserRoute() {
  return defHttp.get<Array<RouteRecordNormalized>>({ url: '/api/auth/current/user/route' });
}

/**
 * 退出
 */
export function doLogout() {
  return defHttp.post({ url: '/api/logout' });
}
